﻿using AbpApplication.InPut;
using AbpToDomain.View;
using Flurl.Http;
using Newtonsoft.Json;
using NewWms.Extend;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wms_wpf.Apiservice;
using wms_wpf;
using AbpApplication.AppServices;
using HandyControl.Controls;
using NewWms.Apiservice.Dto;
using NewWms.Apiservice.InPut;
using Reconstruct_Desktop.Apiservice.Dto;

namespace NewWms.Apiservice
{
    public class ViewService : IViewService
    {
        string config = GlobalVariable.Config;
        public async Task<Tuple<List<View_BoxDto>, long?, long?>> View_Box(InPut_ViewService InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_Box";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<View_BoxDto> res = JsonConvert.DeserializeObject<List<View_BoxDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_Box");
                    return null;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_Box");
                LognetHelper.WriteLog("View_Box", ex);
                return null;
            }
        }
        public async Task<Tuple<List<View_BoxGrid_MaterialDto>, long?, long?>> View_BoxGrid_Material(InPut_ViewService2 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_BoxGrid_Material";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<View_BoxGrid_MaterialDto> res = JsonConvert.DeserializeObject<List<View_BoxGrid_MaterialDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_BoxGrid_Material");
                    return null;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_BoxGrid_Material");
                LognetHelper.WriteLog("View_BoxGrid_Material", ex);
                return null;
            }
        }
        public async Task<List<WarehouseDto>> View_WareHouse()
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_WareHouse";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    List<WarehouseDto> res = JsonConvert.DeserializeObject<List<WarehouseDto>>(Response.Dto.ToString());
                    return res;
                }
                else
                {
                    MessageBox.Warning("获取失败-View_WareHouse");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_WareHouse");
                LognetHelper.WriteLog("View_WareHouse", ex);
                return null;
            }
        }
        public async Task<Tuple<List<WarehouseLineDto>, long?, long?>> View_WareHouseLine(InPut_ViewService3 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_WareHouseLine";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(InPut).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<WarehouseLineDto> res = JsonConvert.DeserializeObject<List<WarehouseLineDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_WareHouseLine");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_WareHouseLine");
                LognetHelper.WriteLog("View_WareHouseLine", ex);
                return null;
            }
        }
        public async  Task<Tuple<List<View_MaterialDto>, long?, long?>> View_Material(InPut_ViewService4 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_Material";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(InPut).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<View_MaterialDto> res = JsonConvert.DeserializeObject<List<View_MaterialDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_Material");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_Material");
                LognetHelper.WriteLog("View_Material", ex);
                return null;
            }
        }
        public async Task<Tuple<List<View_TaskOrderDto>, long?, long?>> View_TaskOrder(InPut_ViewService5 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_TaskOrder"; 
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(InPut).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<View_TaskOrderDto> res = JsonConvert.DeserializeObject<List<View_TaskOrderDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_TaskOrder");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_TaskOrder");
                LognetHelper.WriteLog("View_TaskOrder", ex);
                return null;
            }
        }
        public async Task<Tuple<List<View_Box_WarehouseLineDto>, long?, long?>> View_Box_WarehouseLine(InPut_ViewService6 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_Box_WarehouseLine";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(InPut).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<View_Box_WarehouseLineDto> res = JsonConvert.DeserializeObject<List<View_Box_WarehouseLineDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_Box_WarehouseLineDto");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_Box_WarehouseLineDto");
                LognetHelper.WriteLog("View_Box_WarehouseLineDto", ex);
                return null;
            }
        }
        public async Task<Tuple<List<View_Material_WarehouseLineDto>, long?, long?>> View_Material_WarehouseLine(InPut_ViewService9 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_Material_WarehouseLine";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(InPut).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<View_Material_WarehouseLineDto> res = JsonConvert.DeserializeObject<List<View_Material_WarehouseLineDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_Material_WarehouseLineDto");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_Material_WarehouseLineDto");
                LognetHelper.WriteLog("View_Material_WarehouseLineDto", ex);
                return null;
            }
        }
        public async Task<Tuple<List<View_NeetOutMaterialDto>, long?, long?>> View_NeetOutMaterial(InPut_ViewService10 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_NeetOutMaterial";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(InPut).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<View_NeetOutMaterialDto> res = JsonConvert.DeserializeObject<List<View_NeetOutMaterialDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_NeetOutMaterialDto");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_NeetOutMaterialDto");
                LognetHelper.WriteLog("View_NeetOutMaterialDto", ex);
                return null;
            }
        }
        public async Task<Tuple<List<lognoteDto>, long?, long?>> View_LogNote(InPut_ViewService7 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_LogNote";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(InPut).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<lognoteDto> res = JsonConvert.DeserializeObject<List<lognoteDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-View_LogNote");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-View_LogNote");
                LognetHelper.WriteLog("View_LogNote", ex);
                return null;
            }
        }
        public async Task<Tuple<List<MaterialPropertyhDto>, long?, long?>> View_MaterialProperty(InPut_ViewService8 InPut)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_MaterialProperty";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(InPut).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<MaterialPropertyhDto> res = JsonConvert.DeserializeObject<List<MaterialPropertyhDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    MessageBox.Warning("获取失败-MaterialPropertyhDto");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败-MaterialPropertyhDto");
                LognetHelper.WriteLog("MaterialPropertyhDto:", ex);
                return null;
            }
        }

        public async Task<List<InlethouseLineDto>> View_Inlethouse(string InlethouseCode)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/View_Inlethouse?InlethouseCode={InlethouseCode}";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<InlethouseLineDto> res = JsonConvert.DeserializeObject<List<InlethouseLineDto>>(Response.Dto.ToString());
                    return res;
                }
                else
                {
                    MessageBox.Warning("获取失败- View_Inlethouse");
                    return null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Warning("获取失败- View_Inlethouse");
                LognetHelper.WriteLog(" View_Inlethouse", ex);
                return null;
            }
        }
    }
}
